package com.zsrt.java.day20161223.wrl.demo02;

import java.util.Scanner;

import org.junit.Test;

public class SwitchTest {
	
	/**
	 * ==230 	高铁
	 * ==120	小车
	 * ==40		电动车
	 * else		走路
	 */
	@Test
	public void if01(){
		int speed = 230;
		if(230 == speed){		//230==speed:避免出现空指针异常
			System.out.println("高铁");
		}else if(120 == speed){
			System.out.println("小车");
		}else if(40 == speed){
			System.out.println("电动车");
		}else{
			System.out.println("走路");
		}
	}
	
	/**
	 * 1. break:无论如何都要写
	 * 2. 适用类型：byte/short/long/int/char
	 */
	@Test
	public void switch01(){
		
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入行驶速度：");
		int speed = sc.nextInt();
		sc.close();
		switch (speed) {
			case 230:	System.out.println("高铁...");		break;
			case 120:	System.out.println("小车...");		break;
			case 40:	System.out.println("电动车...");		break;
			default:	System.out.println("走路...");		break;
		}
	}
	
	/**  特殊的类型：String
	 * 
	 * 1. break:无论如何都要写
	 * 2. 适用类型：byte/short/long/int/char /  String
	 * 3. 不管写多少个，有且只有一条语句被执行
	 */
	@Test
	public void switch02(){
		
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入交通工具：");
		String tool = sc.next();
		sc.close();
		switch (tool) {
			case "高铁":		System.out.println("高铁...230");		break;
			case "小车":		System.out.println("小车...120");		break;
			case "电动车":	System.out.println("电动车...40");		break;
			default:		System.out.println("走路...11");		break;
		}
	}
}
